import type { MovePointOptions, MovePointResult } from "./useRectDrag";
import { getIntersectionByLineAndPoint, getRotatePoint } from "/@/utils/draw";

export default function ({
  rotatePoints,
  newPoint,
  rotate,
  lineP1P5,
  width,
  height,
}: MovePointOptions): MovePointResult {
  const targetPoint = getIntersectionByLineAndPoint(rotatePoints[1], lineP1P5, newPoint);
  const rotateCenterPoint = {
    x: rotatePoints[1].x + (targetPoint.x - rotatePoints[1].x) / 2,
    y: rotatePoints[1].y + (targetPoint.y - rotatePoints[1].y) / 2,
  };
  const originalPoint = getRotatePoint(rotateCenterPoint, targetPoint, 360 - rotate);
  const midH = (originalPoint.y - rotateCenterPoint.y) * 2;
  if (midH >= 0) {
    return {
      newHeight: midH,
      newY: rotateCenterPoint.y - midH / 2,
    };
  } else {
    //相当于拖动P5 而且无论怎么拖动 P0P1P2旋转后的位置不会变 都为midH>=0时，P6P5P4旋转后的位置
    return {
      newHeight: -midH,
      newY: rotateCenterPoint.y - -midH / 2,
    };
  }
}
